#!/usr/bin/env bash

source ./config/env.sh
clear

for master_ip in ${MASTER_IP}
do
    echo "=========================================== ${master_ip} ==========================================="
    # create k8s install bin dir
    ssh root@${master_ip} "test -e ${K8S_BIN_DIR} || mkdir -p ${K8S_BIN_DIR}"

    # kubectl 执行文件
    scp ${K8S_DATA}/unpack/kubernetes/client/bin/kubectl root@${master_ip}:${K8S_BIN_DIR}

    # etcd 执行文件
    scp ${K8S_DATA}/unpack/etcd-v3.3.12-linux-amd64/etcd* root@${master_ip}:${K8S_BIN_DIR}

    # flannel 执行文件
    scp ${K8S_DATA}/unpack/flannel/{flanneld,mk-docker-opts.sh} root@${master_ip}:${K8S_BIN_DIR}

    # apiserver 执行文件
    scp ${K8S_DATA}/unpack/kubernetes/server/bin/* root@${master_ip}:${K8S_BIN_DIR}

    # docker 执行文件
    scp ${K8S_DATA}/unpack/docker/docker/* root@${master_ip}:${K8S_BIN_DIR}

    # docker-compose 文件
    scp ${K8S_BIN_DIR}/docker-compose root@${master_ip}:${K8S_BIN_DIR}

    # 设置权限和环境变量
    ssh root@${master_ip} "sudo chmod +x ${K8S_BIN_DIR}/*"
    ssh root@${master_ip} "echo PATH=${K8S_BIN_DIR}:$PATH >> /etc/profile"
    ssh root@${master_ip} "source /etc/profile"
done